﻿using System;

namespace Person
{
    class Person
    {
        private string firstName;
        private string lastName;

        private Genders gender;
        private DateTime birthDate;

        public string FirstName
        {
            get
            {
                return this.firstName;
            }
            set
            {
                this.firstName = value;
                OnFirstNameChanged();
            }
        }
        public string LastName
        {
            get
            {
                return lastName;
            }
            set
            {
                lastName = value;
                OnLastNameChanged();
            }
        }
        public Genders Gender
        {
            get
            {
                return gender;
            }
            set
            {
                gender = value;
                OnGenderChanged();
            }
        }
        public DateTime BirthDate
        {
            get
            {
                return birthDate;
            }
            set
            {
                birthDate = value;
                OnBirthDateChanged();
            }
        }

        private void OnFirstNameChanged()
        {
            if (FirstNameEventHandler != null)
            {
                FirstNameEventHandler(this, null);
            }
        }
        private void OnLastNameChanged()
        {
            if (LastNameEventHandler != null)
            {
                LastNameEventHandler(this, null);
            }
        }
        private void OnGenderChanged()
        {
            if (GenderEventHandler != null)
            {
                GenderEventHandler(this, null);
            }
        }
        private void OnBirthDateChanged()
        {
            if (BirthDateEventHandler != null)
            {
                BirthDateEventHandler(this, null);
            }
        }

        public event EventHandler FirstNameEventHandler;
        public event EventHandler LastNameEventHandler;
        public event EventHandler GenderEventHandler;
        public event EventHandler BirthDateEventHandler;

        public Person()
        {
            InitializeEventHandlers();
        }

        private void InitializeEventHandlers()
        {
            string propChanged = "property was changed.";
            FirstNameEventHandler += ((x, y) => Console.WriteLine("FirstName " + propChanged));
            LastNameEventHandler += ((x, y) => Console.WriteLine("LastName " + propChanged));
            GenderEventHandler += ((x, y) => Console.WriteLine("Gender " + propChanged));
            BirthDateEventHandler += delegate(object sender, EventArgs args)
            {
                Console.WriteLine("BirthDate " + propChanged);
            };
        }
  
    }
}
